<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑比赛成绩</title>
    <script src="../../res/js/jquery-3.4.1.min.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css">
    <script src="../../js/login_common.js"></script>
</head>

<body>
<script>
    var form = null;
    layui.use(['form', 'layedit', 'laydate'], function() {
        var  layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        form = layui.form;


        //日期
        laydate.render({
            elem: '#matchTime'
        });

        loadType();

        $("#creater").val(window.loginObj.user.userName);

        $("#closeSave").on("click",function () {
            //关闭当前层
            //当你在iframe页面关闭自身时
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });


        //点保存按钮
        $("#saveButton").on("click",function (obj) {


            var athleteName = $("#matchName").val();
            if(athleteName==""|| athleteName==null){
                layer.msg("请输入比赛名称");
                return;
            }

            var athleteSelect = $("#athleteId").val();
            if(athleteSelect==""|| athleteSelect==null){
                layer.msg("请选择运动员");
                return;
            }


            //获取运动员名称
            $("#athleteName").val($('#athleteId option:selected').text());

            var fromData = getFormData("fromone");//获取表单数据
            var url = getRootPath() + "AtsEmpAthleteResultsController/insertOrUpdate";

            $.post(url,fromData,function (obj) {
                if(obj.num==1){

                    layer.msg(obj.msg, {
                        icon: 1,
                        time: 500 //0.5秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        //关闭当前层
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        //刷新父页面
                        parent.newLoad();
                    });

                }else{
                    layer.msg(obj.msg);
                }
            },"json");


            return false;
        });
    });

    //加载运动员下拉框
    function loadType(){
        var url = getRootPath() + "AtsEmpAthleteController/findAll";
        var data = null;
        if(window.loginObj.user.companyNum=="2"){
            coachId = window.loginObj.user.filId;
            data = {coachId:coachId};
        }
        $.post(url,data,function (obj) {
            $.each(obj,function (i,item) {
                $("#athleteId").append("<option value='"+item.athleteId+"'>"+item.athleteName+"</option>");
            });

            //判断是不是查看
            var select = getQueryString("select");
            if(select==1) {

                $("#buttonDiv").css("display", "none");

                $(":text").prop("placeholder","");
                $("textarea").prop("placeholder","");

                var forms = document.forms[0];
                for (var i = 0; i < forms.length; i++) {
                    var element = forms.elements[i];
                    //部分元素可以编号     element.name  是元素自定义 name
                    if (element.name != "auditEntity.auditContent"
                        && element.name != "auditEntity.auditAutograph"
                        && element.name != "auditEntity.auditTime"
                        && element.name != "auditEntity.auditState"
                        && element.name != "submitBtn"
                        && element.name != "reset"
                        && element.name != "id"
                        && element.name != "processInstanceId"
                        && element.name != "updateForm") {
                        element.disabled = "true";
                    }
                }
            }

            var id = getQueryString("id");
            if (id !="" && id!=null) {
                findByid(id);
            }

            form.render();
        },"json");
    }

    function findByid(id) {
        var url = getRootPath() + "AtsEmpAthleteResultsController/findById";
        var data = {id:id};
        $.post(url,data,function (obj) {
            $("#athleteId").val(obj.athleteId);
            $("#resultId").val(obj.resultId);
            $("#matchName").val(obj.matchName);
            $("#matchTime").val(obj.matchTime);
            $("#matchAddr").val(obj.matchAddr);
            $("#matchItem").val(obj.matchItem);
            $("#matchResult").val(obj.matchResult);
            $("#matchSort").val(obj.matchSort);
            $("#score").val(obj.score);
            $("#addr").val(obj.addr);
            $("#other").val(obj.other);
            form.render();
        },"json");
    }

</script>

<form class="layui-form" action="" id="fromone">

    <input id="resultId" name="resultId" type="hidden">
    <input id="athleteName" name="athleteName" type="hidden">
    <input id="creater" name="creater" type="hidden">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">比赛名称</label>
            <div class="layui-input-block">
                <input type="text" name="matchName" id="matchName" lay-verify="title" autocomplete="off" placeholder="请输入比赛名称" class="layui-input" maxlength="128">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">比赛时间</label>
            <div class="layui-input-block">
                <input type="text" name="matchTime" id="matchTime" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">比赛地点</label>
            <div class="layui-input-block">
                <input type="text" name="matchAddr" id="matchAddr" lay-verify="title" autocomplete="off" placeholder="请输入比赛地点" class="layui-input" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">比赛项目</label>
            <div class="layui-input-block">
                <input type="text" name="matchItem" id="matchItem" lay-verify="title" autocomplete="off" placeholder="请输入比赛项目" class="layui-input" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">比赛成绩</label>
            <div class="layui-input-block">
                <input type="text" name="matchResult" id="matchResult" lay-verify="title" autocomplete="off" class="layui-input" placeholder="请输入比赛成绩" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">比赛排名</label>
            <div class="layui-input-block">
                <input type="text" name="matchSort" id="matchSort" lay-verify="title" autocomplete="off" class="layui-input" placeholder="请输入比赛排名" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">积分</label>
            <div class="layui-input-block">
                <input type="text" name="score" id="score" lay-verify="title" autocomplete="off" class="layui-input" placeholder="请输入积分" maxlength="128">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">运动员</label>
            <div class="layui-input-inline">
                <select name="athleteId" id="athleteId" lay-verify="required" lay-search="">
                    <option value=""></option>
                </select>
            </div>
        </div>
    </div>

    <div class="layui-form-item" id="buttonDiv">
        <div class="layui-input-block">
            <input type="button" value="保存" class="layui-btn" id="saveButton">
            <input type="button" value="取消" class="layui-btn layui-btn-primary" id="closeSave">
        </div>
    </div>

</form>
</body>
</html>